/*
 * @Descripttion: 
 * @version: 
 * @Author: kk
 * @Date: 2020-10-24 09:19:07
 * @LastEditors: kk
 * @LastEditTime: 2020-10-27 10:52:24
 */
import axios from 'axios'
import Element from 'element-ui'
import router from './router'
import store from './store'

axios.defaults.baseURL = "http://localhost:9001";


//前置拦截
axios.interceptors.request.use(config => {
    config.headers.Authentication=localStorage.getItem("token");
    return config;
},error => {
    return Promise.reject(error);
});

//后置拦截
axios.interceptors.response.use(response => {
    let res = response.data;
    console.log("----------");
    console.log(res);
    console.log("----------");
    if (res.code === 200) {
        return res;
    } else {
        //登录错误则清空本地的token
        Element.Message.error(res.message, {duration: 3 * 1000});
        //store.commit("REMOVE_INFO");    
        return Promise.reject(response.data.message);
    }
}, error => {
    console.log(error.response);
    if (error.response.data){
        error.message=error.response.data.message;
    }
    return Promise.reject(error.response.data.message);
    
});
export default axios
